import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:travel/screen/flutter_screenutil.dart';
import 'package:travel/ui/draw_under_line.dart';
import 'package:travel/utils/colors.dart';
import 'package:travel/utils/styles.dart';
import 'package:travel/utils/tools.dart';

class MsgController extends GetxController {
  RxBool isOrder = true.obs;

  RxBool isInteract = true.obs;

  RxList<String> tabs = RxList(['所有人', '互相关注的驴友', '不接收私信']);

  RxInt tabIndex = 0.obs;
}

class MsgView extends GetView<MsgController> {
  const MsgView({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
          backgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF7f7),
          appBar: AppBar(
            automaticallyImplyLeading: true,
            leading: InkWell(
              onTap: () {
                Get.back();
              },
              child: Icon(
                Icons.arrow_back_ios,
                color: ColorsUtils.parseColorFromHexString(ColorsUtils.color3333),
                size: 20.w,
              ),
            ),
            leadingWidth: 40.w,
            title: Text(
              '消息设置',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color3333, fontSize: 18.sp, fontWeight: FontWeight.bold),
            ),
          ),
          body: SingleChildScrollView(
            padding: EdgeInsets.symmetric(vertical: 20.h, horizontal: 15.w),
            child: Column(
              children: [
                Container(
                  padding: EdgeInsets.only(left: 15.w, bottom: 15.h),
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '通知设置',
                    style:
                        StylesUtils.customTextStyle(color: ColorsUtils.color9999, fontSize: 13.sp),
                  ),
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 15.w),
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: ListBody(
                    children: [
                      DrawUnderLine(
                        color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF5f5),
                        child: SizedBox(
                          height: 50.h,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                '订单消息',
                                style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color3333, fontSize: 15.sp),
                              ),
                              IconButton(
                                  style: ButtonStyle(
                                      overlayColor: MaterialStateColor.resolveWith(
                                              (states) => Colors.transparent)),
                                  onPressed: () {
                                    controller.isOrder.value = !controller.isOrder.value;
                                  },
                                  icon: ToolsUtils.assetImageSvg(
                                      activeSvg(controller.isOrder.value),
                                      width: 45,
                                      height: 24))
                            ],
                          ),
                        ),
                      ),
                      SizedBox(
                        height: 50.h,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '互动消息',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color3333, fontSize: 15.sp),
                            ),
                            IconButton(
                                style: ButtonStyle(
                                    overlayColor: MaterialStateColor.resolveWith(
                                        (states) => Colors.transparent)),
                                onPressed: () {
                                  controller.isInteract.value = !controller.isInteract.value;
                                },
                                icon: ToolsUtils.assetImageSvg(
                                    activeSvg(controller.isInteract.value),
                                    width: 45,
                                    height: 24))
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(left: 15.w, bottom: 15.h),
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '谁可以私信我',
                    style:
                        StylesUtils.customTextStyle(color: ColorsUtils.color9999, fontSize: 13.sp),
                  ),
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 15.w),
                  decoration:
                      BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.w)),
                  child: ListBody(
                    children: controller.tabs
                        .asMap()
                        .map((index, name) => MapEntry(
                            index,
                            Stack(
                              children: [
                                InkWell(
                                  onTap: () {
                                    if (controller.tabIndex.value != index) {
                                      controller.tabIndex.value = index;
                                    }
                                  },
                                  child: Container(
                                    height: 50.h,
                                    alignment: Alignment.centerLeft,
                                    child: Text(
                                      name,
                                      style: StylesUtils.customTextStyle(
                                          color: ColorsUtils.color3333, fontSize: 16.sp),
                                    ),
                                  ),
                                ),
                                if (controller.tabIndex.value == index)
                                  Positioned(
                                      width: 20.w,
                                      top: 0,
                                      right: 0,
                                      bottom: 0,
                                      child: Center(
                                          child: ToolsUtils.assetImageSvg('u2548.svg',
                                              width: 20.w, height: 15.h)))
                              ],
                            )))
                        .values
                        .toList(),
                  ),
                )
              ],
            ),
          ),
        ));
  }

  String activeSvg(bool value) {
    if (value) {
      return 'u2551.svg';
    }
    return 'u2552.svg';
  }
}
